Skip to content

Fix Identity's ctrl_adder#1781

Merged
mhucka merged 4 commits intoquantumlib:mainfrom
petim0:identity_fix
Jan 9, 2026
Merged

Fix Identity's ctrl_adder#1781
mhucka merged 4 commits intoquantumlib:mainfrom
petim0:identity_fix

Conversation

@petim0
Copy link
Copy Markdown
Contributor

@petim0 petim0 commented Dec 12, 2025

Identity is a special bloq: its controlled version is still an identity, but with a larger register, ie. calling Identity(n).controlled(CtrlSpec(QAny(m))) gets us Identity(n+m)

The old version of ctrl_adder() was using Autopartition which failed during decomposition as Autopartition is not designed to merge registers and pass them to the inner bloq.

This is fixed by this PR by replacing Autopartition with Partition(s).

This fix is functional but the resulting show_bloq() output is less clean as the Partition steps are visible. An alternative (maybe better) fix is to keep using Autopartition but mark the control registers as Unused(), but It is weird conceptually to not use Identity(n+m) as the controlled Identity.

This PR also adds a test covering this bug.

@petim0
Copy link
Copy Markdown
Contributor Author

petim0 commented Dec 12, 2025

This is the show_bloq that is less clean:
Screenshot 2025-12-12 at 16 41 09

@petim0 petim0 changed the title Fixed Identity's ctrl_adder Fix Identity's ctrl_adder Dec 16, 2025
Copy link
Copy Markdown
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I agree this is probably the right fix

@mpharrigan
Copy link
Copy Markdown
Collaborator

can you run

check/format-incremental --apply

to format the code.

There's also a mypy type checking problem in the unit test. Since this is a unit test, you can add a # type: ignore comment if it's not obvious how to fix it. You can run the type checker with check/mypy.

@mhucka mhucka merged commit d2f8baa into quantumlib:main Jan 9, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants